// pages/report_detail/report.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    reportArr: [],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //读取数据
    setListData: function () {
      let that = this;
      var reportArr = app.globalData.reportArr

      // console.log(reportArr)
      that.setData({
        reportArr: reportArr
      });
      app.globalData.reportArr = [];
      this.calculationLeft(reportArr)
    },
    //left 计算
    calculationLeft: function (obj) {
      var that = this
      console.log(obj)
      // var obj = obj || {}
      // console.log(obj)
      for (var i = 0; i < obj.length; i++) {
        for (var j = 0; j < obj[i].secArr1.length; j++) {
          if (obj[i].secArr1[j].displaytype == 3) {
            var max = Number(obj[i].secArr1[j].highStandard) + (Number(obj[i].secArr1[j].highStandard) - Number(obj[i].secArr1[j].lowStandard))
            var min = Number(obj[i].secArr1[j].lowStandard) - (Number(obj[i].secArr1[j].highStandard) - Number(obj[i].secArr1[j].lowStandard))
            var count = max - min
            var now = Number(obj[i].secArr1[j].description)
            var nows = now - min
            console.log(max, min, now, nows)
            obj[i].secArr1[j].left = nows / count * 100
          }
        }
      }

      // console.log(arr)
      that.setData({
        reportArr: obj
      })
    },
    //打开
    openClick: function (e) {
      var that = this
      var index = e.currentTarget.dataset.index
      var idx = e.currentTarget.dataset.idx
      var reportArr = that.data.reportArr
      reportArr[idx].project[index].open = true
      that.setData({ reportArr: reportArr })
    },
    //关闭
    closeClick: function (e) {
      var that = this
      var index = e.currentTarget.dataset.index
      var idx = e.currentTarget.dataset.idx
      var reportArr = that.data.reportArr
      reportArr[idx].project[index].open = false
      that.setData({ reportArr: reportArr })
    },
    //异常
    abnormalClick: function () {
      var myEventDetail = {} // detail对象，提供给事件监听函数
      this.triggerEvent('abnormal', myEventDetail)
    },
    //推荐
    suggestion: function () {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/suggestion/suggestion',
      })
    }
  },
  ready: function () {
    this.setListData();

  }
})
